package com.woniuxy.hrp.web;

import com.woniuxy.hrp.entity.Doctor;
import com.woniuxy.hrp.entity.Mitem;
import com.woniuxy.hrp.entity.PageBean;
import com.woniuxy.hrp.mapper.MitemMapper;
import com.woniuxy.hrp.service.MitemService;
import com.woniuxy.hrp.unityhandler.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description：
 * @Author：曹杰克
 * @CreateTime：2022/9/6 20:14
 */
@RestController
@RequestMapping("/api/v1/mitem")
public class MitemController {
    @Autowired
    private MitemService mitemService;
    /**
     * desc:获取所有的检查项目
     * @Param:  * @param
     * @Return: []
     * @Author: caojieke
     * @Date: 2022/9/6 20:13
     */
   @RequestMapping("/getAllMitem")
    public ResponseEntity<List<Mitem>> getAllMitem() {
        List<Mitem> allMitem = mitemService.getAllMitem();
        return new ResponseEntity<>("200","ok",allMitem);
    }


    //管理员：查询检查项目
    @RequestMapping("/list")
    public ResponseEntity<List<Mitem>> getMitem() {
        List<Mitem> listMitem = mitemService.getAllMitem();
        return new ResponseEntity("200", "success", listMitem);
    }

    //管理员：增加检查项目
    @RequestMapping("/add")
    public ResponseEntity addItem(@RequestBody Mitem mitem) {
       mitemService.add(mitem);
        return new ResponseEntity("200", "success", "加入的id为" + mitem.getId());
    }

    //管理员：删除检查项目（逻辑）
    @RequestMapping("/del/{id}")
    public ResponseEntity delItem(@PathVariable (value = "id")int id) {
       mitemService.delete(id);
        return new ResponseEntity("200", "success","删除成功");

    }

    //管理员：查询检查项目(根据ID)
    @RequestMapping("/select/{id}")
    public ResponseEntity<Mitem> selectItem(@PathVariable (value = "id")int id) {
        Mitem mitem =  mitemService.findById(id);
        return new ResponseEntity("200","OK",mitem);

    }


    //管理员：修改更新检查项目（只有价格可以修改，名字和描述不可以）
    @RequestMapping("/update")
    public ResponseEntity updateItem(@RequestBody Mitem mitem) {
        mitemService.update(mitem.getId());
        return new ResponseEntity("200", "success", "更新的id为" + mitem.getId());
    }


    // 管理员功能：查询所有的检查项目列表(带分页功能)
    @GetMapping("/selectAll/{current}/{limit}")
    public ResponseEntity selectAll(@PathVariable(value="current")int current, @PathVariable (value="limit")int limit){
        PageBean<Mitem> pageBean = mitemService.getByPage(current,limit);
        return new ResponseEntity(ResponseEntity.SUCCESS.getCode(),ResponseEntity.SUCCESS.getMsg(),pageBean);
    }
}


